package com.jill.Controller;

import com.jill.Pojo.Result;
import com.jill.Pojo.User;
import com.jill.Service.UserService;
import com.jill.utils.JwtUtils;
import com.jill.utils.Mail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;
    // 用户登录
    @PostMapping("/login")
    public Result login( @RequestBody User user){
        User userInfo=userService.login(user);
        String token=JwtUtils.GenerateToken(userInfo.getUsername(),userInfo.getPassword());
        Map<String, Object> result=new HashMap<>();
        result.put("token",token);
        result.put("userInfo",userInfo);
        return Result.success(result);
    }
    // 验证码
    @GetMapping("/validCode")
    public Result getValidCode(String mail){

        String validCode=UUID.randomUUID().toString();

        Mail.sendMail(mail,validCode);

        return Result.success(validCode);
    }
}
